﻿function $id(ele) {
    return document.getElementById(ele);
}

///填充版本列表
addLoadFuc(fillVersion);
function fillVersion() {
    var v = ns.GetVersions().value;
    if (v == null || v.Rows.length == 0) return;
    var count = v.Rows.length;
    var sel = $id("id_sel_vers");
    for (var i = 0; i < count; i++) {
        sel.options.add(new Option(v.Rows[i].VER, v.Rows[i].VER));
    }
}

///获取指定过程信息
function getProcess() {
    var sel = $id("id_sel_vers");
    var ver = sel.options[sel.selectedIndex].value;
    var dt = ns.GetProcessInfo(ver).value;
    if (dt == null) {
        alert("没有相关数据 !");
        return;
    }
    $id("id_ipt_proc_id").value = dt[0];
    $id("id_ipt_proc_name").value = dt[1];
    $id("id_ipt_per").value = dt[3];
    $id("id_ipt_start_date").value = dt[4];
    $id("id_ipt_end_date").value = dt[5];
    if (dt[6] == "Y") {
        $id("id_act").checked = true;
        $id("id_forbid").checked = false;
    } else {
        $id("id_act").checked = false ;
        $id("id_forbid").checked = true;
    }
}

//保存修改
function  saveModify() {
    var list = new Array();
    list[0] = $id("id_ipt_proc_id").value;
    list[1] = $id("id_ipt_proc_name").value;
    if (dateCompare($id("id_ipt_end_date").value, $id("id_ipt_start_date").value)) {
        alert("过期日期必须在生效日期后面 !");
        return;
    }
    list[2] = $id("id_ipt_start_date").value+" 00:00:00";
    list[3] = $id("id_ipt_end_date").value+" 23:59:59";
    if ($id("id_act").checked == true) {
        list[4] = "Y";
    } else {
        list[4] = "N";
    }
    alert(ns.SaveChanged(list).value);
}
function clearAll() {
    $id("id_ipt_proc_id").value = "";
    $id("id_ipt_proc_name").value = "";
    $id("id_ipt_per").value = "";
    $id("id_ipt_start_date").value = "";
    $id("id_ipt_end_date").value = "";
    $id("id_forbid").checked = false;
    $id("id_act").checked = false;
    $id("id_sel_vers").selectedIndex = 0;
}

function dateCompare(startStr, endStr) {
    var d1, d2, s, arr, arr1, arr2;
    if (startStr.length > 10) {
        arr = startStr.split(" ");
        arr1 = arr[0].split("-");
        arr2 = arr[1].split(":");
        d1 = new Date(arr1[0], arr1[1] - 1, arr1[2], arr2[0], arr2[1], arr2[2]);
    }
    else {
        arr = startStr.split("-");
        d1 = new Date(arr[0], arr[1], arr[2]);
    }

    if (endStr.length > 10) {
        arr = endStr.split(" ");
        arr1 = arr[0].split("-");
        arr2 = arr[1].split(":");
        d2 = new Date(arr1[0], arr1[1] - 1, arr1[2], arr2[0], arr2[1], arr2[2]);
    }
    else {
        arr = endStr.split("-");
        d2 = new Date(arr[0], arr[1], arr[2]);
    }

    s = d2 - d1;
    if (s < 0) {
        return false;
    }
    return true;
}